// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require(CONFIG.BasePath + "js/enterprise/base");
	var router = require("../hash/pageRouter");
	var constant = require("constant");
	var css_detail = require("./accountRecordModify.css");
	var databind = require("databind");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var init = function() {
		router.init();
		showList("queryEnterpriseModifyPageLists.json");
		initEvent();
	};

	var initEvent = function() {
		if (base.getData("sid") == null) {
			location.href = "../login/login.html";
		}

		$("#applyType span").click(function() {
			$("#applyType span").removeClass("active_applyType");
			$(this).addClass("active_applyType");
			$(this).parent().removeClass("applyType1").removeClass("applyType2").removeClass("applyType3").removeClass("applyType4").removeClass("applyType5").removeClass("applyType6");
			$(this).parent().addClass($(this).attr("applytype"));
			$("#accountRecordApplySearchButton").attr("action", $(this).attr("action"));
			showList($(this).attr("action"));
		});

		$("#accountRecordApplySearchButton").unbind("click").click(function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化				
			showList($(this).attr("action"));
		});
	};

	//申请列表
	var showList = function(action) {
		if ($("#financeStateApply").val() != -1) {
			var financeState = $("#financeStateApply").val();
		}
		var dateBegin = $("#dateBegin").val();
		var dateEnd = $("#dateEnd").val();
		base.fnAjax({
			action: action,
			async: false,
			oData: {
				enterpriseType: 0,
            	pageIndex: pageIndex,
                pageSize: pageSize
			}, //传递参数
			fnSuccess: function(data) {
		         if (data.status == 200) {
	                	juicer.register("getValueByKey", constant.getValueByKey);
	                	
	                	var tpl = $("#accountRecordApplyListTpl").html();
	                    var html = juicer(tpl, data);
	                    $("#accountRecordApplyListBody").html(html);
	                    totalPageCount = data.totalPageCount;
	                    totalRecordCount = data.totalRecordCount;
	                    base.pageControl(
	                    	$("#changepage"),
	                        totalRecordCount,
	                        data.pageIndex,
	                        data.pageSize,
	                        function(p) {
	                            pageIndex = p;
	                            showList();
	                    });
	                    
	                     //点击详情
				        $("#accountRecordApplyListBody").on("click",".table_details_link",function(){
				           var authenticationIds = [];
				           var $this = $(this).parents("tr.tr_style");
				           authenticationIds.push($this.attr("authenticationId"));
							router.route("account/clienManage_details.html?authenticationId="+authenticationIds,true);
				        });							
	                } else {
	                    base.alert(2,"信息获取失败");
	                }
			}
		});
	};
	
	return {
		init: init
	};
});